from curl_cffi import requests
import execjs

cookies = {
    'qpfccr': 'true',
    'sessionid': '4t0jw5uevwgakbfu6m1t2s22ai6aj68o',
    'Hm_lvt_c99546cf032aaa5a679230de9a95c7db': '1720594330,1720595661,1720602423',
    'HMACCOUNT': 'CC1B9ED2B8CFB10A',
    'no-alert3': 'true',
    'Hm_lvt_9bcbda9cbf86757998a2339a0437208e': '1720594359,1720598310,1720602436',
    'Hm_lvt_434c501fe98c1a8ec74b813751d4e3e3': '1720592198,1720595529,1720602544',
    'HMACCOUNT': 'CC1B9ED2B8CFB10A',
    'Hm_lpvt_434c501fe98c1a8ec74b813751d4e3e3': '1720602558',
    'Hm_lpvt_9bcbda9cbf86757998a2339a0437208e': '1720602633',
    'Hm_lpvt_c99546cf032aaa5a679230de9a95c7db': '1720602633',
}

headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    # 'Cookie': 'qpfccr=true; sessionid=4t0jw5uevwgakbfu6m1t2s22ai6aj68o; Hm_lvt_c99546cf032aaa5a679230de9a95c7db=1720594330,1720595661,1720602423; HMACCOUNT=CC1B9ED2B8CFB10A; no-alert3=true; Hm_lvt_9bcbda9cbf86757998a2339a0437208e=1720594359,1720598310,1720602436; Hm_lvt_434c501fe98c1a8ec74b813751d4e3e3=1720592198,1720595529,1720602544; HMACCOUNT=CC1B9ED2B8CFB10A; Hm_lpvt_434c501fe98c1a8ec74b813751d4e3e3=1720602558; Hm_lpvt_9bcbda9cbf86757998a2339a0437208e=1720602633; Hm_lpvt_c99546cf032aaa5a679230de9a95c7db=1720602633',
    'Pragma': 'no-cache',
    'Referer': 'https://match.yuanrenxue.cn/match/1',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
    'X-Requested-With': 'XMLHttpRequest',
    'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}

params = {
    'm': '15af9abe5548347b553254b8e698c2d9丨1720702635',
    'page': 1
}

ctx = {};
with open('./code.js', 'r', encoding = 'utf-8') as f:
    code = f.read()
    ctx = execjs.compile(code)

total_price = 0
count = 0
for i in range(1, 6):
    params['m'] = ctx.call('get_m')
    params['page'] = i
    response = requests.get('https://match.yuanrenxue.cn/api/match/1', params=params, cookies=cookies, headers=headers, verify=False, impersonate = "chrome110")
    result = response.json()
    if result['status'] != '1':
        print('request faild:', params)
        continue

    data = result['data']
    for value in data:
        total_price += value['value']
        count += 1

print(total_price/count)
